home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 3.7 KB | 135 lines | [TEXT/ttxt] |
- --<<<
- -- Filename:
- -- axis.sx
-
- -- Other Files Required:
- -- none
-
- -- Purpose:
- -- axis.sx defines abstract classes for building the axes of the grapher tool.
-
- -- Specialized Classes:
- -- Axis
-
- -- Instructions to User:
- -- The axis class is a group of presenters that define the length
- -- of the axis, the minimum and maximum value labels, and the axis label.
-
- -- Author:
- -- Dionn Stewart. Revised by Ray Davis.
-
- -- The axis class associates an abstract axis, the minimum and maximum value labels,
- -- the axis label, and the current property of the axis. That is, it collects
- -- those elements which will be changed when the property graphed on the axis
- -- changes.
- -- Formats and placements of the labels are left up to the grapher.
- -- The axis must be presented by a grapher object.
- in module Autofinder
-
- class Axis (GroupSpace)
- instance variables
- origin -- origin of axis in pixel offset
- length -- length of axis, used to determine pixel/value scale
- minLabel -- presenter to display the minimum value
- maxLabel -- presenter to display the maximum value
- axisLabel -- an AxisLabel that must provide Actuator capabilities
- property -- an AxisProperty that the axis will represent
- scale -- scale in pixels for the current property
- end
-
- method init self {class Axis} #rest args #key \
- origin:(0) \
- length:(undefined) \
- minLabel:(new TextPresenter boundary:(new Rect x2:50 y2:18) target:"" \
- fill:whiteBrush stroke:blackBrush) \
- maxLabel:(new TextPresenter boundary:(new Rect x2:50 y2:18) target:"" \
- fill:whiteBrush stroke:blackBrush) \
- axLabel: ->
- (
- apply nextMethod self args
- self.axisLabel := axLabel
- self.origin:= origin
- self.length:= length
- self.minLabel := minLabel
- self.maxLabel := maxLabel
- self
- )
-
- method afterInit self {class Axis} #rest args #key \
- property:(undefined) ->
- (
- local minLabel, maxLabel, labelFont
-
- apply nextMethod self args
-
- -- set text attributes for min and max labels
- minLabel := self.minLabel
- maxLabel := self.maxLabel
- labelFont := new platformfont name:"Palatino"
-
- setDefaultAttr minLabel @font labelFont
- setDefaultAttr minLabel @size 10
- setDefaultAttr minLabel @alignment @center
- setDefaultAttr minLabel @leading 12
-
- setDefaultAttr maxLabel @font labelFont
- setDefaultAttr maxLabel @size 10
- setDefaultAttr maxLabel @alignment @center
- setDefaultAttr maxLabel @leading 12
-
- changeProperty self property
-
- -- Bundle the parts of the axis together
- append self minLabel
- append self maxLabel
- append self self.axisLabel
-
- -- Make the actuator controller for the axis label
- local ac:= new actuatorController space:self
- append ac self.axisLabel
- self
- )
-
- -- Changing the property of the axis, so update the presenters
- -- and re-graph the objects currently shown.
- -- This is usually called by the Grapher's propertyMenu.
- method changeProperty self {class Axis} prop ->
- (
- self.property := prop
- if prop <> undefined do
- (
- setLabels self prop
- local val := prop.maxValue - prop.minValue
- if (val <> 0) then
- self.scale := self.length/val
- else
- self.scale := 0
- )
-
- -- Let our presenter know that graphable objects must be rearranged
- -- on the graph
- if self.presentedBy <> undefined do
- refreshGraph self.presentedBy
- )
-
- -- Update the labels to present the new property
- method setLabels self {class Axis} prop ->
- (
- self.minLabel.target:= prop.minTarget
- self.maxLabel.target:= prop.maxTarget
- self.axisLabel.target:= prop.axisTarget
- prop
- )
-
- -- This method returns a pixel offset that corresponds to the property
- -- value where prop is the graph property and val is the value to
- -- be translated
- method scaleValue self {class Axis} prop val ->
- (
- local diff:= max 0 (val - prop.minValue)
- (diff * self.scale) as integer
- )
-
- "Compiled axis.sx"
- -->>>
-